package common

import (
	"github.com/gin-gonic/gin"
)

// BindJSON 统一绑定并返回错误
func BindJSON[T any](c *gin.Context) (*T, bool) {
	var req T
	if err := c.ShouldBindJSON(&req); err != nil {
		c.AbortWithStatusJSON(200, gin.H{"code": 400, "msg": "请求参数有误: " + err.Error()})
		return nil, false
	}
	return &req, true
}
